package cn.iocoder.yudao.module.handguard.controller.app.orders;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.handguard.controller.app.orders.vo.OrdersInfoResVo;
import cn.iocoder.yudao.module.handguard.controller.app.orders.vo.OrdersResVo;
import cn.iocoder.yudao.module.handguard.controller.app.orders.vo.TJOrderResVo;
import cn.iocoder.yudao.module.handguard.dal.dataobject.usertablesaudit.UserTablesAuditDO;
import cn.iocoder.yudao.module.handguard.service.applicationrecord.ApplicationRecordService;
import cn.iocoder.yudao.module.handguard.service.usertablesaudit.UserTablesAuditService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUser;

/**
 * @author: liuweijun
 * @since: 2023/9/13 16:09
 * @description:
 */
@Tag(name = "小程序 - 客户列表")
@RestController
@RequestMapping("/orders")
@Validated
public class OrdersController {

    @Resource
    private ApplicationRecordService applicationRecordService;

    @Resource
    private UserTablesAuditService userTablesAuditService;

    @GetMapping("/tj/list")
    @Operation(summary = "推荐人-订单列表")
    public CommonResult<List<TJOrderResVo>> getTjClientList() {
        //当前用户id
        Long userId = getLoginUser().getId();
        List<TJOrderResVo> orderList = applicationRecordService.getTjClientList(userId);
        return success(orderList);
    }

    @GetMapping("/list")
    @Operation(summary = "业务员-订单列表")
    @Parameter(name = "status", description = "1:待跟进，2:跟进中，3:完成", required = true, example = "1")
    public CommonResult<List<OrdersResVo>> getClientList(@RequestParam("status") Integer status) {
        //当前用户id
        Long userId = getLoginUser().getId();
        List<OrdersResVo> ordersResVoList = applicationRecordService.getClientList(userId,status);
        return success(ordersResVoList);
    }

    @GetMapping("/warrant-list")
    @Operation(summary = "权证-订单列表")
    @Parameter(name = "status", description = "1:待跟进，2:跟进中，3:完成", required = true, example = "1")
    public CommonResult<List<OrdersResVo>> getWarrantList(@RequestParam("status") Integer status) {
        //当前用户id
        Long userId = getLoginUser().getId();
        List<OrdersResVo> ordersResVoList = applicationRecordService.getWarrantList(userId,status);
        return success(ordersResVoList);
    }

    @GetMapping("/info")
    @Operation(summary = "业务员、权证-订单详情")
    @Parameter(name = "orderId", description = "订单id", required = true, example = "1")
    public CommonResult<OrdersInfoResVo> getClientInfo(@RequestParam("orderId") Long orderId) {
        OrdersInfoResVo infoResVo = applicationRecordService.getAppClientInfo(orderId);
        return success(infoResVo);
    }


    @GetMapping("/dataList")
    @Operation(summary = "完善资料列表")
    @Parameter(name = "id", description = "订单id", required = true, example = "1")
    public CommonResult<Map<String,List<UserTablesAuditDO>>> getOrderDataList(Long id) {
        Map<String,List<UserTablesAuditDO>> listMap = userTablesAuditService.getOrderDataList(id,1);
        return success(listMap);
    }

    @GetMapping("/dataLists")
    @Operation(summary = "完善资料列表-驳回后不通过的项")
    @Parameter(name = "id", description = "订单id", required = true, example = "1")
    public CommonResult<Map<String,List<UserTablesAuditDO>>> getOrderDataListTwo(Long id) {
        Map<String,List<UserTablesAuditDO>> listMap = userTablesAuditService.getOrderDataList(id,0);
        return success(listMap);
    }

}
